Contents | Index | < Browse | Browse >

LETTERclockULETTER Measures CPU time used by the program.

Overview
#include <time.h>

x = clock(void);

clock_t x;

Portability
ANSI

Description
"clock" returns the processor time used by this program. Unfortunately it would be too much afford to calculate the correct CPU time used by the program as this would require to log each task-switching. The function only returns the time passed since the start of the program. The result can be converted to seconds by dividing through "CLOCKS_PER_SEC".

Returns
The time passed since the program was started.

See also
system , time

Example
#include <time.h>
#include <math.h>
#include <stdio.h>

void main(void)
{
clock_t start, end;
double index;

start = clock();

for(index = 1.0; index <= 1000.0; ++index)
(void) log(index);

end = clock();
// Calculate the difference between the two times
printf("Difference %d\\n",(end-start) / CLOCKS_PER_SEC);
}